from django.db import models
from django.db.models.base import ModelState
from django.utils import timezone
# Create your models here.

Type = (
    (0, 'Single select'),
    (1, 'Multi select')
)
Option = (
    (1, 'A'),
    (2, 'B'),
    (3, 'C'),
    (4, 'D'),
    (5, 'E'),
)

ScoreRule = (
    (1, 5),
    (2, 4),
    (3, 3),
    (4, 2),
    (5, 1),
)


class TestPaper(models.Model):
    title = models.CharField(max_length=512, verbose_name='testpaper_title')
    description = models.CharField(max_length=1024, verbose_name='testpaper_description', blank=True)
    create_at = models.DateTimeField("CreateTime", default=timezone.now)
    
class Subject(models.Model):
    title = models.CharField(max_length=1024, verbose_name='subject_content', blank=False, null=False)
    type = models.IntegerField(choices=Type, verbose_name='quesion_type')
    testpaper = models.ForeignKey('TestPaper', on_delete=models.CASCADE, blank=True)
    ops = models.ManyToManyField('Options', blank=True)

class Options(models.Model):
    options = models.IntegerField(choices=Option, verbose_name='itemsABCDE')
    content = models.CharField(max_length=256, verbose_name='opsContent')

    class Meta:
        ordering = ["options"]

class AnswerPaper(models.Model):
    testee = models.CharField(max_length=32, verbose_name='testee name', blank=False)
    email = models.EmailField(blank=False)
    telphone = models.CharField(max_length=11, verbose_name='phone', blank=False)
    scores = models.PositiveSmallIntegerField(verbose_name='paper scores', blank=True)
    start_time = models.DateTimeField("CreateTime", default=timezone.now, blank=True)
    finish_time = models.DateTimeField("FinishTime", default=timezone.now, blank=True)
    comment= models.CharField(max_length=1024, blank=True)
    testpaper = models.ForeignKey(TestPaper, on_delete=models.CASCADE, blank=True)
    valid = models.BooleanField(default=False)

class Answer(models.Model):
    sub_id = models.IntegerField(verbose_name='subject_id')
    options = models.IntegerField(choices=Option, verbose_name='itemsABCDE')
    answerpaper = models.ForeignKey('AnswerPaper', on_delete=models.CASCADE, blank=True)
